//
//  QNewFeatureVC.m
//  QoilPublic
//
//  Created by 杨凯 on 16/7/4.
//  Copyright © 2016年 杨凯. All rights reserved.
//

#import "QNewFeatureVC.h"
#import "QNewFeatureCell.h"

static NSString * const reuseIdentifier = @"Cell";

@interface QNewFeatureVC ()

@property (nonatomic, weak) UIPageControl *control;

@end

@implementation QNewFeatureVC

- (instancetype)init{
    UICollectionViewFlowLayout *follayout = [[UICollectionViewFlowLayout alloc] init];
    follayout.minimumLineSpacing = 0;
    follayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    follayout.itemSize = [[UIScreen mainScreen] bounds].size;
    
    return [super initWithCollectionViewLayout:follayout];
}

#pragma mark --- viewDidLoad
- (void)viewDidLoad {
    [super viewDidLoad];
    self.collectionView.pagingEnabled = YES;
    self.collectionView.bounces = NO;//弹的效果
    self.collectionView.showsHorizontalScrollIndicator = NO;
    [self.collectionView registerClass:[QNewFeatureCell class] forCellWithReuseIdentifier:reuseIdentifier];
    
    [self setUpPageControl];
}

- (void)setUpPageControl{
    UIPageControl *control = [[UIPageControl alloc] init];
    control.numberOfPages = 3;
    control.pageIndicatorTintColor = [UIColor colorWithRed:104/255.0 green:126/255.0 blue:241/255.0 alpha:0.3];
    control.currentPageIndicatorTintColor = [UIColor colorWithRed:104/255.0 green:126/255.0 blue:241/255.0 alpha:1];
    control.center = CGPointMake(self.view.width * 0.5, self.view.height-20);
    _control = control;
    [self.view addSubview:control];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    int page = scrollView.contentOffset.x / scrollView.bounds.size.width;
    _control.currentPage = page;
}

#pragma mark --- UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 3;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    QNewFeatureCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    
    NSString *imgString = [NSString stringWithFormat:@"starindex_%ld",(long)indexPath.row];
    cell.images = [UIImage imageNamed:imgString];
    [cell setIndexPath:indexPath count:3];
    return cell;
}

@end
